import request from '@/utils/request';
import type { BaseBeanModel, ResponsePageData, ResponseBaseData, QueryParamModel, TreeNodeModel } from '@/api/model/baseModel';
import type { downloadParam } from '@/utils/download-util';
import { download } from '@/utils/download-util';
const basePath = '/bpm/bpmmodel';
export interface ProcessModelDto extends BaseBeanModel {
  categoryId?: string;
  flowName?: string;
  isUflow?: string;
  flowDesc?: string;
}

export function listBpmModelByPage(param: QueryParamModel): Promise<ResponsePageData<any>> {
  return request.post(`/bpm/bpmpi/bpmpiprocesss/searchBpmPiModelByPage/v1`, param);
}
/**
 * 子过程选择页面
 * @param param
 * @returns
 */
export function listSubBpmModelByPage(param: QueryParamModel): Promise<ResponsePageData<any>> {
  return request.post(`/bpm/bpmpi/bpmpiprocesss/searchSubBpmPiModelByPage/v1`, param);
}
/** 删除活动 */
export function deleteProcess(param: object[]): Promise<ResponseBaseData<any>> {
  return request.post(`/bpm/bpmpi/bpmpiprocesss/deleteProcess/v1`, param);
}

export function saveBpmModel(param: any): Promise<ResponseBaseData<any>> {
  return request.post(`/bpm/bpmpi/bpmpiprocesss/saveBpmPiModel/v1`, param);
}

/**
 * 导出
 * @param param 导出参数
 */
export function exportExcel(param: any, fileName: string) {
  const downloadData = {
    url: `/bpm/design/downJpdl/v1`,
    data: param,
    method: 'post',
    fileName
  } as downloadParam;
  return download(downloadData);
}

/** 发布 */
export function deployFlow(id: string): Promise<ResponseBaseData<any>> {
  return request.post(`/bpm/bpmpi/bpmpiprocesss/deployFlow/v1?id=${id}`);
}

/** 启用 */
export function startProcessTemplate(id: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/operate/startProcessTemplate/v1?id=${id}`);
}

/** 停用 */
export function suspendedProcessTemplate(id: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/operate/suspendedProcessTemplate/v1?id=${id}`);
}

/** 权限设置 */
export function setFlowModelPermission(param: any): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/operate/setFlowModelPermission/v1`, param);
}

/** 启用手动发起流程 */
export function permitManualStart(id: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/operate/permitManualStart/v1?id=${id}`);
}

/** 禁止手动发起流程 */
export function forbidManualStart(id: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/operate/forbidManualStart/v1?id=${id}`);
}

/** 设置排序 */
export function updateBpmModelOrder(param: any): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/appBpmModelRest/updateBpmModelOrder/v1`, param);
}

/** 切换分组树选择数据 */
export function getManagerTree(param: any): Promise<ResponseBaseData<TreeNodeModel[]>> {
  return request.post(`/eformvue/dynamicform/DynamicTreeRest/getManagerTree/v1`, param);
}

/** 切换分组 */
export function updateBpmRelation(param: any): Promise<ResponseBaseData<any>> {
  return request.post(`/bpm/bpmpi/bpmpiprocesss/updateBpmRelation/v1`, param);
}

/** 获取组织列表 */
export function getOrgList(): Promise<ResponseBaseData<any>> {
  return request.get(`/appsys/user/multiorg/list/org`);
}

/** 共享 */
export function share(param: any): Promise<ResponseBaseData<any>> {
  return request.post(`/eformvue/dynamicform/DynamicOrgMapRest/insert/v1`, param);
}

/** 共享流程 */
export function shareFlow(param: any): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/appBpmModelRest/processSharing/v1`, param);
}

/** 复制流程 */
export function saveCopyFlow(param: any): Promise<ResponseBaseData<any>> {
  return request.post(`bpm/bpmpi/bpmpiprocesss/copyBpmModel/v1`, param);
}

export function testStartProcess(): Promise<ResponseBaseData<any>> {
  return request.get('/bpm/bpmpi/test/testStartProcess/v1');
}
